package com.springboot.others.service.impl;

import com.springboot.others.entity.UserMybatis;
import com.springboot.others.mapper.UserMybatisMapper;
import com.springboot.others.service.UserMybatisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@CacheConfig(cacheNames = "users")
public class UserMybatisServiceImpl  implements UserMybatisService {

    @Autowired
    private UserMybatisMapper userMybatisMapper;

    @Cacheable
    @Override
    public List<UserMybatis> findByName(String name){
        return userMybatisMapper.findByName(name);
    }


    @CachePut
    @Override
    public int insert(String name,Integer age){
        return userMybatisMapper.insert(name, age);
    }

//    @CachePut(key="#p0.id")
    @Override
    public UserMybatis insert2(UserMybatis userMybatis){
         userMybatisMapper.insert2(userMybatis);
         return userMybatis;
    }

    @CacheEvict(allEntries=true)
    @Override
    public  int deleteAll(){
        return userMybatisMapper.deleteAll();
    }

//    @CacheEvict
    @Override
    public  int deleteOne(Long id){
        return userMybatisMapper.deleteOne(id);
    }


}